package www.way2inbox.settings;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.preference.EditTextPreference;
import android.preference.PreferenceManager;
import android.util.AttributeSet;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;

public class CustomEdittextPreference extends EditTextPreference {
	Editor editor;
	String showSignature;
	private CheckBox cbShowSign;
	private SharedPreferences preferences;

	public CustomEdittextPreference(Context context, AttributeSet attrs) {
		super(context, attrs);
		preferences = PreferenceManager.getDefaultSharedPreferences(context);
		editor = preferences.edit();
	}

	@Override
	protected void onBindView(View view) {
		super.onBindView(view);
		showSignature = ApplicationConstants.SettingsPreferenceKeys.GEN_SIGNATURE_SHOW;
		cbShowSign = (CheckBox) view.findViewById(android.R.id.checkbox);
		if (preferences.getBoolean(showSignature, true)) {
			cbShowSign.setChecked(true);
		} else {

			cbShowSign.setChecked(false);

		}
		cbShowSign.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (preferences.getBoolean(showSignature, true)) {

					editor.putBoolean(showSignature, false);
					editor.commit();
					cbShowSign.setChecked(false);
					System.out.println(">>unchecked>>"
							+ preferences.getBoolean(showSignature, true));
				} else {

					editor.putBoolean(showSignature, true);
					editor.commit();
					cbShowSign.setChecked(true);
					System.out.println(">>checked>>"
							+ preferences.getBoolean(showSignature, true));

				}

			}
		});

	}

}
